package org.wang.portal;

import org.wang.portal.core.OperationContext;
import org.wang.portal.core.OperationStrategyFactory;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        if (args.length > 0) {
            // 启动参数指定模式
            executeWithArgs(args);
        } else {
            // 命令行人机交互模式
            executeWithUserInput();
        }
    }

    /**
     * 启动参数指定模式
     */
    private static void executeWithArgs(String[] args) {
        OperationContext context = new OperationContext();
        String mode = args[0]; // 第一个参数指定模式
        context.setStrategy(OperationStrategyFactory.createStrategy(mode));
        context.executeStrategy(args);
        System.out.println("Exiting Portal process...");
        System.exit(0);
    }

    /**
     * 命令行人机交互模式
     */
    private static void executeWithUserInput() {
        Scanner scanner = new Scanner(System.in);
        OperationContext context = new OperationContext();
        // 启动或停止 Kafka
        System.out.println("Do you want to operate Kafka? (kafka)(start/stop)");
        System.out.println("Do you want to run task ?(task) (create/delete/update/query/start/stop)");
        System.out.println("Do you want to Orchestrate Task? (orchestrate) ");
        String portalAction = scanner.nextLine();
        context.setStrategy(OperationStrategyFactory.createStrategy(portalAction));
        context.executeStrategy(new String[]{portalAction, scanner.nextLine()});
        System.out.println("Exiting Portal process...");
        System.exit(0);
    }
}